<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>用户登陆</title>
	<link rel="icon" href="../../img/icon.png" type="image/x-icon"/>
	<link rel="stylesheet" type="text/css" href="../../../css/mui.css"/>
	<link rel="stylesheet" type="text/css" href="../../../css/mui.min.css"/>
	<link rel="stylesheet" type="text/css" href="../../../css/app.css"/>
</head>
<body>
	<!-- 头部TITLE -->
	<header class="mui-bar mui-bar-nav mui-bar-transparent">
		<span class="mui-icon mui-icon-back" onclick="mui.back()"></span>
		<h1 class="mui-title">登陆</h1>
	</header>
	<!-- 头部TITLE -->
	
	<!-- 主体部分 -->
	<div style="height: 100px;"></div>
	<div class="form">
		<h2>用户登陆</h2>
		<input type="text" id="phone" placeholder="手机号码" value="15988129456"/>
		<input type="text" id="pwd" placeholder="密码6-20位，数字字母组合" value="123456"/>
<!-- 		<input type="text" id="phone" placeholder="手机号码"/>
		<input type="text" id="pwd" placeholder="密码6-20位，数字字母组合"/> -->
		<input type="button" value="登陆" onclick="setLogin()"/>
		<input type="button" value="没账号？去注册" onclick="jumpToMyRegist()"/>
	</div>
	<!-- 主体部分 -->
	
	<!-- 底部菜单 -->
	<nav class="mui-bar mui-bar-tab">
		<a class="mui-tab-item" onclick="jumpToIndex()">
			<span class="mui-icon mui-icon-home"></span>
			<span class="mui-tab-label">首页</span>
		</a>
		<a class="mui-tab-item" onclick="jumpToMarket()">
			<span class="mui-icon mui-icon-download"></span>
			<span class="mui-tab-label">库</span>
		</a>
<!-- 		<a class="mui-tab-item" onclick="jumpToMarket()">
			<span class="mui-icon mui-icon-download"></span>
			<span class="mui-tab-label">广场</span>
		</a> -->
<!-- 		<a class="mui-tab-item" onclick="jumpToCamera()">
			<span class="mui-icon mui-icon-camera"></span>
			<span class="mui-tab-label">拍</span>
		</a> -->
<!-- 		<a class="mui-tab-item" onclick="jumpToChat()">
			<span class="mui-icon mui-icon-chatbubble"></span>
			<span class="mui-tab-label">消息</span>
		</a> -->
		<a class="mui-tab-item mui-active" onclick="jumpToMy()">
			<span class="mui-icon mui-icon-contact"></span>
			<span class="mui-tab-label">我的</span>
		</a>
	</nav>
	<!-- 底部菜单 -->
</body>
</html>


<script src="../../../js/mui.js"></script>
<script src="../../../js/app.js"></script>
<script type="text/javascript">
	// 登陆
	function setLogin(){
		var phone = mui("#phone")[0].value;
		var pwd = mui("#pwd")[0].value;
		if (!phone || !pwd) {
			mui.toast('手机号码或密码未填',{ 
				duration:'long', type:'div',
			});
			return
		}
		if(!(/^1[3456789]\d{9}$/.test(phone))){
			mui.toast('手机号码格式错误',{ 
				duration:'long', type:'div',
			});
			return
		} 
		if(!(/^[0-9a-zA-Z_]{6,20}$/.test(phone))){
			mui.toast('密码格式错误',{ 
				duration:'long', type:'div',
			});
			return
		} 
		// 系统参数
		var sys = getSys();
		// if (sys==null || sys.appAccess=='') { 
		// 	setSys(); //参数更新
		// 	setTimeout(function(){
		// 		jumpToMyLogin();
		// 	}, 1000);
		// } 
		// mui.toast(sys.appAccess,phone,pwd); return
		mui.ajax(sys.domain+'/app/user/login',{
			data:{
				appAccess: sys.appAccess,
				phone:phone,
				pwd:pwd
			},
			dataType:'json', //服务器返回json格式数据
			type:'post', //HTTP请求类型
			timeout:10000, //超时时间设置为10秒
			headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
			success:function(res){
				// mui.toast('res：'+res.code); return
				if (res.code==-1) {
					mui.toast('需要更新系统参数',{ 
						duration:'long', type:'div',
					});
					setTimeout(function(){
						setSys();
						jumpToMyLogin();
					},500);
				} else if (res.code!=0) {
					mui.toast(res.msg+'！',{ 
						duration:'long', type:'div',
					});
					return
				}
				var userInfo = {
					uid:res.data.uid,
					name:res.data.name,
					phone:res.data.phone,
					head:res.data.head,
					appHead:res.data.appHead,
					headBg:res.data.headBg,
					appHeadBg:res.data.appHeadBg,
					detail:res.data.detail
				};
				// 更新用户信息缓存
				cacheSet(userInfoKey, userInfo);
				// 登陆成功，跳转到我的页面
				setTimeout(function(){
					jumpToMy();
				}, 1000);
			},
			error:function(xhr,type,errorThrown){
				mui.toast('网络错误！',{ 
					duration:'short', type:'div',
				});
			}
		});
	}
</script>